package com.haste.controller;

import com.haste.pojo.Dept;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName:DeptController
 * @Description:
 * @Author:Haste
 * @Date:2021/2/2 9:31
 */
@RestController
public class DeptController {
    @Resource
    private RestTemplate restTemplate;
    //因该设置变量，不应该写死
    //private static final String REST_URL_PREFIX = "http://localhost:8001";
    //Eureka中的Application就是
    private static final String REST_URL_PREFIX = "http://PROVIDER-DEPT";
    @RequestMapping(value = "/consumer/dept/get/{deptId}",method = RequestMethod.GET)
    public Dept get(@PathVariable("deptId") Long deptId){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+deptId,Dept.class);
    }

    @RequestMapping(value = "/consumer/dept/add",method = RequestMethod.POST)
    public boolean add(@RequestBody Dept dept){
        return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add",dept,Boolean.class);
    }

    @RequestMapping(value = "/consumer/dept/list",method = RequestMethod.GET)
    public List<Dept> list(){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list",List.class);
    }
}
